<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn">点击</button>

    <script>
      function once(fn) {
        var called = false;
       
        return function () {
          if (!called) {
            called = true;
           fn.call(this)
          }
        };
      }

      document.getElementById('btn').onclick = once(function (event) {
        console.log('调用了');
        console.log(this);
      });

      //once(),调用
      //fn = function (event) {console.log('调用了')}
      // 返回  function () { if (!called)
    </script>
  </body>
</html>
